<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 加息平台管理模块
 */
class Interests extends Admin_Controller {
	
    function __construct()
    {
        parent::__construct();
        $this->load->model('plat_model');
    }
    //理财平台AB类型列表
    public function index()
    {
        $where = array();
        $st = trim($_GET['st']);
        $key = trim($_GET['key']);
        if ($key != '') {
            if ($st == 1) {
                $con = '平台中文名称';
                $where['name_ch'] = $key;
            }
            if ($st == 2) {
                $con = '平台英文名称';
                $where['name_en'] = $key;
            }
        }
        if (trim($_GET['time-start']) && trim($_GET['time-end'])) {
            $time_start = strtotime($_GET['time-start']);
            $time_end = strtotime($_GET['time-end']) + 3600 * 24;
            $where['plat.create_time <= '] = $time_end;
            $where['plat.create_time >= '] = $time_start;
        }
//        $where['is_interest_mode'] = 1;//加息模式
        //分页
        $getcount = $this->plat_model->getCount($where);
        $navigation_position = 'outside';
        $records_per_page = 10;
        $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
        //$this->xpage->reverse(true);
        $this->xpage->records($getcount);
        $this->xpage->records_per_page($records_per_page);
        $this->xpage->labels("<<", ">>");
        $list = $this->plat_model->getList($where, (($this->xpage->get_page() - 1) * $records_per_page) ,$records_per_page);
        foreach($list as $key=>$val){
            $list[$key]['plat_interest'] = ($val['plat_interest'] * 100)."%";
            $list[$key]['add_interest'] = (floatval($val['add_interest']) * 100)."%";
            $info = $this->db->query("select * from tan_plat_info where plat_en = '$val[name_en]' order by id desc limit 1")->row_array();
            $list[$key]['plat_info'] = $info;
        }
        //------------------
        $this->template->assign('stname', $st);
        $this->template->assign('keyname', trim($_GET['key']));
        $this->template->assign('conname', $con);
        $this->template->assign('time_start', trim($_GET['time-start']));
        $this->template->assign('time_end', trim($_GET['time-end']));
        $this->template->assign('Total',$getcount);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/index');
    }
    
    //加息任务
    function tasks(){
        $where = "1=1";
        if($_GET['st'] && $_GET['q']){
            $st = trim($_GET['st']);
            $key = trim($_GET['q']);
            switch ($st){
                case "id":
                    $where .= " and t.id = ".  decrypt_interests_id($key);
                    $st_name = "投资编号";
                    break;
                case "plat":
                    $plat = $this->db->query("select id,plat_en from tan_plat_info where plat_ch like '%$key%' order by id desc limit 1")->row_array();
                    $plat = $plat ? $plat : array("plat_en"=>"");
                    $where .= " and t.plat_en = '$plat[plat_en]'";
                    $st_name = "平台名称";
                    break;
                case "name":
                    $user = $this->db->query("select user_id,username from tan_users where username = '$key' order by user_id desc limit 1")->row_array();
                    $user = $user ? $user : array('user_id'=>0);
                    $where .= " and t.user_id = $user[user_id]";
                    $st_name = "用户名";
                    break;
            }
            $this->template->assign('st_type', $st);
            $this->template->assign('st_name', $st_name);
            $this->template->assign('key_name', $key);
        }
        $getcount = $this->db->query("select * from tan_plat_invest_task t left join tan_plat_info i on i.plat_en = t.plat_en left join tan_users u on u.user_id = t.user_id where $where order by t.id desc")->num_rows();
        $navigation_position = 'outside';
        $records_per_page = 10;
        $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
        $this->xpage->records($getcount);
        $this->xpage->records_per_page($records_per_page);
        $this->xpage->labels("<<", ">>");
        $query_params = "t.id,t.title,t.user_id,t.oid_id,t.total_amount,t.amount,t.total_interest_finance,t.invest_time,t.add_interest,t.extra_interest,t.status,i.plat_ch,u.username,l.rate";
        $list = $this->db->query("select $query_params from tan_plat_invest_task t left join tan_plat_invest_list l on l.id = t.invest_id left join tan_plat_info i on i.plat_en = t.plat_en left join tan_users u on u.user_id = t.user_id where $where order by t.id desc limit ".(($this->xpage->get_page() - 1) * $records_per_page).",".$records_per_page)->result_array();
        foreach ($list as $key=>$val){
            $list[$key]['aid'] = encrypt_interests_id($val['id']);
            $list[$key]['add_interest'] = ($val['add_interest'] * 100)."%";
            $list[$key]['extra_interest'] = $val['extra_interest'] ? ($val['extra_interest'] * 100)."%" : 0;
            $list[$key]['rate'] = $val['rate'] ? ($val['rate'])."%" : 0;
            $list[$key]['invest_time'] = date("Y-m-d H:i:s",$val['invest_time']);
        }
        $this->template->assign('Total',$getcount);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->assign('segment_p','tasks');
        $this->template->load('interests/tasks');
    }
    //加息明细
    function tasks_detail(){
        $task_id = isset($_GET['id']) ? decrypt_interests_id(trim($_GET['id'])) : 0;
        $item = $this->db->query("select t.*,i.plat_ch,u.username from tan_plat_invest_task t left join tan_plat_info i on i.plat_en = t.plat_en left join tan_users u on u.user_id = t.user_id where t.id = $task_id order by t.id desc limit 1")->row_array();
        if(!$item){
            redirect("interests/tasks_detail");
        }
        $item['aid'] = encrypt_interests_id($task_id);
        $getcount = $this->db->query("select * from tan_plat_interest_detail where invest_id = $item[invest_id] order by id desc")->num_rows();
        $navigation_position = 'outside';
        $records_per_page = 10;
        $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
        $this->xpage->records($getcount);
        $this->xpage->records_per_page($records_per_page);
        $this->xpage->labels("<<", ">>");
        $list = $this->db->query("select * from tan_plat_interest_detail where invest_id = $item[invest_id] order by id desc limit ".(($this->xpage->get_page() - 1) * $records_per_page).",".$records_per_page)->result_array();
        foreach ($list as $key=>$val){
            $list[$key]['create_time'] = date("Y-m-d",$val['create_time']);
        }
        
        $this->template->assign('item',$item);
        $this->template->assign('Total',$getcount);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->assign('segment_p','tasks');
        $this->template->load('interests/tasks_detail');
    }
    //平台信息修改
    function modify(){
        if($_POST){
            $plat_id = trim($_POST['plat_id']);
            $plat_en = trim($_POST['plat_en']);
            $plat_data = array();
            $plat_data['plat_interest'] = trim($_POST['plat_interest']);
            $plat_data['add_interest'] = trim($_POST['add_interest']);
            $plat_data['plat_interest_desc'] = trim($_POST['plat_interest_desc']);
            $plat_data['exper_require_desc']  = trim($_POST['exper_require_desc']);
            $plat_data['min_require_amount'] = trim($_POST['min_require_amount']);
            $plat_data['max_require_amount'] = trim($_POST['max_require_amount']);
            $plat_data['require_amount_desc'] = trim($_POST['require_amount_desc']);
            $plat_data['min_require_period'] = trim($_POST['min_require_period']);
            $plat_data['max_require_period'] = trim($_POST['max_require_period']);
            $plat_data['require_period_type'] = trim($_POST['require_period_type']);
            $plat_data['require_period_desc'] = trim($_POST['require_period_desc']);
            
            $result = $this->db->where(array("id"=>$plat_id))->update("tan_plat",$plat_data);
            if($result){
                update_cache("platlist");
                $plat_info_data = array();
                $plat_info_data['pingtaiduibitu'] = $_POST['pingtaiduibitu'];
                $plat_info_data['total_person'] = $_POST['total_person'];
                $plat_info_data['total_amount'] = $_POST['total_amount'];
                $this->db->where(array("plat_en"=>$plat_en))->update("tan_plat_info",$plat_info_data);
                
                $mssage['info']	  = '操作成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
        
        $plat_id = trim($_GET['id']);
        $query_params = "p.id,p.name_en,p.plat_interest,p.add_interest,p.plat_interest_desc,p.exper_require_desc,p.max_require_amount,p.min_require_amount,p.require_amount_desc,p.min_require_period,p.max_require_period,p.require_period_type,p.require_period_desc,i.pingtaiduibitu,i.total_amount,i.total_person";
        $item = $this->db->query("select $query_params from tan_plat p left join tan_plat_info i on p.name_en = i.plat_en where p.id = $plat_id order by p.id desc limit 1")->row_array();
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/edit');
    }
    //更新平台/股东背景
    function modify_plat_bg(){
        if($_POST){
            $mssage = array();
            $plat_en	   = trim($_POST['plat_en']);
            $plat_bg_str = trim($_POST['plat_bg_str']);
            $data = array();
            $data['plat_bg_str'] = $plat_bg_str;
            
            $result = $this->db->where("plat_en",$plat_en)->update("plat_info",$data);
            if($result){
                update_cache("platlist");
                $mssage['info']	  = '成功设置';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
    }
    //更新平台/股东背景
    function modify_plat_ywlx(){
        if($_POST){
            $mssage = array();
            $plat_en	   = trim($_POST['plat_en']);
            $plat_ywlx_str = trim($_POST['plat_ywlx_str']);
            $data = array();
            $data['plat_ywlx_str'] = $plat_ywlx_str;
            $result = $this->db->where("plat_en",$plat_en)->update("plat_info",$data);
            if($result){
                $mssage['info']	  = '成功设置';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
    }
    //设置理财平台是否推荐
    function setrecommend(){
        if($_GET){
            $mssage = array();
            $plat_id	   = trim($_GET['id']);
            $is_recommend = trim($_GET['recommend']);
            $data = array();
            $data['is_recommend'] = $is_recommend;
            $result = $this->plat_model->update_plat($data,$plat_id);
            if($result){
                $mssage['info']	  = '设置成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }

        }	
    }
    //设置理财平台加息模式
    function setmode(){
        if($_GET){
            $mssage = array();
            $plat_id	   = trim($_GET['id']);
            $is_interest_mode = trim($_GET['mode']);
            $data = array();
            $data['is_interest_mode'] = $is_interest_mode;
            if($is_interest_mode == 0){
                $data['is_interest_mode'] = 0;
            }
            $result = $this->plat_model->update_plat($data,$plat_id);
            if($result){
                update_cache("platlist");
                if($is_interest_mode==1){
                    $mssage['info']	  = '成功设置';
                }else{
                    $mssage['info']	  = '成功取消';
                }
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }

        }	
    }
    //企业信息
    function qiyexinxi(){
        if($_POST){
            $name_en = trim($_POST['plat_en']);
            $data = array();
            $data['company_bg_type'] = $_POST['company_bg_type'];
            $data['company'] = $_POST['company'];
            $data['reg_capital'] = $_POST['reg_capital'];
            $data['ICP'] = $_POST['ICP'];
            $data['setup_time'] = $_POST['setup_time'];
            $data['managed_funds'] = $_POST['managed_funds'];
            $data['domain_name'] = $_POST['domain_name'];
            $data['domain_time'] = $_POST['domain_time'];
            $data['business_type'] = $_POST['business_type'];
            $data['company_type'] = $_POST['company_type'];
            $data['finance_info'] = $_POST['finance_info'];
            $data['reg_address'] = $_POST['reg_address'];
            $result = $this->db->where(array("plat_en"=>$name_en))->update("plat_baseinfo",$data);
            if($result){
                update_cache("platlist");
                $qiyexinxi = serialize($data);
                $this->db->where(array("plat_en"=>$name_en))->update("plat_info",array("qiyexinxi"=>$qiyexinxi));
                $mssage['info']	  = '设置成功';
                $mssage['status'] = 1;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
        }
        $plat_en = trim($_GET['key']);
        $item = $this->db->query("select b.*,p.name_ch from tan_plat_baseinfo b left join tan_plat p on p.name_en = b.plat_en where b.plat_en = '$plat_en' order by b.id desc limit 1")->row_array();
        $this->template->assign('bgtype',  $this->bgType);
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/qiyexinxi');
    }
    //团队介绍-列表
    function tuanduijieshao(){
        $plat_en = trim($_GET['key']);
        //分页
        $getcount = $this->db->query("select * from tan_plat_team where plat_en = '$plat_en' order by id")->num_rows();
        $navigation_position = 'outside';
        $records_per_page = 10;
        $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
        $this->xpage->records($getcount);
        $this->xpage->records_per_page($records_per_page);
        $this->xpage->labels("<<", ">>");
        $list = $this->db->query("select * from tan_plat_team where plat_en = '$plat_en' order by sort desc,id desc limit ".(($this->xpage->get_page() - 1) * $records_per_page).",".$records_per_page)->result_array();
        $item = $this->db->query("select name_ch,name_en from tan_plat where name_en = '$plat_en' order by id limit 1")->row_array();
        
        $this->template->assign('item',$item);
        $this->template->assign('Total',$getcount);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/tuanduijieshao');
    }
    //团队介绍-列表
    function tuanduijieshao_add(){
        if($_POST){
            $plat_en = trim($_POST['plat_en']);
            $data = array();
            $data['plat_en'] = $plat_en;
            $data['name'] = $_POST['name'];
            $data['position'] = $_POST['position'];
            $data['head_img'] = $_POST['head_img'];
            $data['introduction'] = $_POST['introduction'];
            $data['sort'] = $_POST['sort'];
            $data['is_show'] = $_POST['is_show'];
            $this->db->insert("plat_team",$data);
            $insert_id = $this->db->insert_id();
            if($insert_id){
                $this->update_tuanduijieshao($plat_en);
                $mssage['info']	  = '添加成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url('interests/tuanduijieshao')."?key=".$plat_en;
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
        }
        $plat_en = trim($_GET['key']);
        $item = $this->db->query("select name_ch,name_en from tan_plat where name_en = '$plat_en' order by id limit 1")->row_array();
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/tuanduijieshao_add');
    }
    //团队介绍-列表
    function tuanduijieshao_edit(){
        if($_POST){
            $plat_en = trim($_POST['plat_en']);
            $id = trim($_POST['id']);
            $data = array();
            $data['plat_en'] = $plat_en;
            $data['name'] = $_POST['name'];
            $data['position'] = $_POST['position'];
            $data['head_img'] = $_POST['head_img'];
            $data['introduction'] = $_POST['introduction'];
            $data['sort'] = $_POST['sort'];
            $data['is_show'] = $_POST['is_show'];
            $result = $this->db->where(array("id"=>$id))->update("plat_team",$data);
            if($result){
                $this->update_tuanduijieshao($plat_en);
                $mssage['info']	  = '更新成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url('interests/tuanduijieshao')."?key=".$plat_en;
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
        }
        $teamm_id = trim($_GET['id']);
        $item = $this->db->query("select t.*,p.name_ch from tan_plat_team t left join tan_plat p on p.name_en = t.plat_en where t.id = '$teamm_id' order by t.id desc limit 1")->row_array();
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/tuanduijieshao_edit');
    }
    //团队介绍-更新show
    function tuanduijieshao_setshow(){
        if($_GET){
            $mssage = array();
            $id	   = trim($_GET['id']);
            $is_show = trim($_GET['is_show']);
            $plat_en = trim($_GET['key']);
            $data = array();
            $data['is_show'] = $is_show;
            $result = $this->db->where(array("id"=>$id))->update("plat_team",$data);
            if($result){
                $this->update_tuanduijieshao($plat_en);
                if($is_index==1){
                    $mssage['info']	  = '显示成功';
                }else{
                    $mssage['info']	  = '隐藏成功';
                }
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }

        }
    }
    //团队介绍-更新排序
    function tuanduijieshao_setsort(){
        if($_POST){
            $mssage = array();
            $id    = trim($_POST['id']);
            $sort  = trim($_POST['sort']);
            $plat_en = trim($_POST['key']);
            if(!$id){
                    $mssage['info']	  = '系统错误';
                    $mssage['status'] = 0;
                    $mssage['url']	  = '';
                    echo json_encode($mssage);exit;
            }

            $data = array();
            $data['sort'] = $sort;
            $result = $this->db->where(array("id"=>$id))->update("plat_team",$data);
            if($result){
                $this->update_tuanduijieshao($plat_en);
                $mssage['info']	  = '操作成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
    }
    //团队介绍-更新del
    function tuanduijieshao_setdel(){
        if($_GET){
            $mssage = array();
            $id	   = trim($_GET['id']);
            $plat_en	   = trim($_GET['key']);
            $data = array();
            $this->db->where(array("id"=>$id))->delete("plat_team");
            $result = $this->db->affected_rows();
            if($result){
                $this->update_tuanduijieshao($plat_en);
                $mssage['info']	  = '删除成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
    }
    //公司介绍
    function gongsijieshao(){
        if($_POST){
            $name_en = trim($_POST['plat_en']);
            $data = array();
            $data['description'] = $_POST['description'];
            $result = $this->db->where(array("plat_en"=>$name_en))->update("plat_info",$data);
            if($result){
                $mssage['info']	  = '设置成功';
                $mssage['status'] = 1;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
        }
        $plat_en = trim($_GET['key']);
        $item = $this->db->query("select i.*,p.name_ch from tan_plat_info i left join tan_plat p on p.name_en = i.plat_en where i.plat_en = '$plat_en' order by i.id desc limit 1")->row_array();
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/gongsijieshao');
    }
    //平台费用
    function pingtaifeiyong(){
        if($_POST){
            $name_en = trim($_POST['plat_en']);
            $data = array();
            $data['manage_fee'] = $_POST['manage_fee'];
            $data['recharge_fee'] = $_POST['recharge_fee'];
            $data['cash_fee'] = $_POST['cash_fee'];
            $data['vip_fee'] = $_POST['vip_fee'];
            $data['zhuanrang_fee'] = $_POST['zhuanrang_fee'];
            $data['pay_type'] = $_POST['pay_type'];
            $result = $this->db->where(array("plat_en"=>$name_en))->update("plat_fee",$data);
            if($result){
                $pingtaifeiyong = serialize($data);
                $this->db->where(array("plat_en"=>$name_en))->update("plat_info",array("pingtaifeiyong"=>$pingtaifeiyong));
                $mssage['info']	  = '设置成功';
                $mssage['status'] = 1;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
        }
        $plat_en = trim($_GET['key']);
        $item = $this->db->query("select f.*,p.name_ch from tan_plat_fee f left join tan_plat p on p.name_en = f.plat_en where f.plat_en = '$plat_en' order by f.id desc limit 1")->row_array();
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/pingtaifeiyong');
    }
    //图片资料
    function tupianziliao(){
        $plat_en = trim($_GET['key']);
        $type = $_GET['type'] ? trim($_GET['type']) : "credit";
        $where = "type = '$type' and plat_en = '$plat_en'";
        //分页
        $getcount = $this->db->query("select * from tan_plat_info_img where $where order by id")->num_rows();
        $navigation_position = 'outside';
        $records_per_page = 10;
        $this->xpage->navigation_position(isset($navigation_position) && in_array($navigation_position, array('left', 'right')) ? $navigation_position : 'outside');
        $this->xpage->records($getcount);
        $this->xpage->records_per_page($records_per_page);
        $this->xpage->labels("<<", ">>");
        $list = $this->db->query("select * from tan_plat_info_img where $where order by sort desc,id desc limit ".(($this->xpage->get_page() - 1) * $records_per_page).",".$records_per_page)->result_array();
        
        $item = $this->db->query("select p.name_ch,p.name_en from tan_plat p where p.name_en = '$plat_en' order by p.id desc limit 1")->row_array();
        $this->template->assign('Total',$getcount);
        $this->template->assign('showpage',$this->xpage->render(true));
        $this->template->assign('list',$list);
        $this->template->assign('tt',$type);
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/tupianziliao');
    }
    //接口管理
    function interfac(){
        if($_POST){
            $plat_en = trim($_POST['plat_en']);
            $plat_id = trim($_POST['plat_id']);
            $data = array();
            $data['reg_link'] = trim($_POST['reg_link']);
            $data['login_link'] = trim($_POST['login_link']);
            $data['h5_reg_link'] = trim($_POST['h5_reg_link']);
            $data['h5_login_link'] = trim($_POST['h5_login_link']);
            $data['simple_success_invest_link'] = trim($_POST['simple_success_invest_link']);
            $data['success_invest_link'] = trim($_POST['success_invest_link']);
            $data['invest_amount_link'] = trim($_POST['invest_amount_link']);
            $result = $this->db->where("plat_en",$plat_en)->update("plat_interface",$data);
            if($result){
                $plat_data = array();
                $plat_data['is_fast_reg'] = trim($_POST['is_fast_reg']);
                $plat_data['is_fast_login'] = trim($_POST['is_fast_login']);
                $this->db->where("id",$plat_id)->update("plat",$plat_data);
                
                $mssage['info']	  = '添加成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
        $plat_en = trim($_GET['key']);
        $item = $this->db->query("select f.*,p.name_ch,p.is_fast_login,p.id plat_id,is_fast_reg from tan_plat_interface f left join tan_plat p on p.name_en = f.plat_en where f.plat_en = '$plat_en' order by f.id desc limit 1")->row_array();
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/interfac');
    }
    //体验规则
    function tiyanguize(){
        if($_POST){
            $plat_en = trim($_POST['plat_en']);
            $data = array();
            $data['tiyanguize'] = trim($_POST['tiyanguize']);
            $result = $this->db->where("plat_en",$plat_en)->update("plat_info",$data);
            if($result){
                
                $mssage['info']	  = '添加成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
        $plat_en = trim($_GET['key']);
        $item = $this->db->query("select i.plat_ch,i.plat_en,i.tiyanguize from tan_plat_info i where i.plat_en = '$plat_en' order by i.id desc limit 1")->row_array();
        $this->template->assign('item',$item);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/tiyanguize');
    }
    
    //图片资料-添加
    function tupianziliao_add(){
        if($_POST){
            $plat_en = trim($_POST['plat_en']);
            $type = trim($_POST['type']);
            $data = array();
            $data['plat_en'] = $plat_en;
            $data['title'] = $_POST['title'];
            $data['type'] = $type;
            $data['image_url'] = $_POST['image_url'];
            $data['sort'] = $_POST['sort'];
            $data['is_show'] = $_POST['is_show'];
            $this->db->insert("plat_info_img",$data);
            $insert_id = $this->db->insert_id();
            if($insert_id){
                $this->update_tupianziliao($plat_en,$type);
                $mssage['info']	  = '添加成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url('interests/tupianziliao')."?key=".$plat_en."&type=".$type;
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
        }
        $plat_en = trim($_GET['key']);
        $type = trim($_GET['type']);
        $item = $this->db->query("select name_ch,name_en from tan_plat where name_en = '$plat_en' order by id limit 1")->row_array();
        $this->template->assign('item',$item);
        $this->template->assign('tt',$type);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/tupianziliao_add');
    }
    //图片资料-编辑
    function tupianziliao_edit(){
        if($_POST){
            $plat_en = trim($_POST['plat_en']);
            $type = trim($_POST['type']);
            $id = trim($_POST['id']);
            $data = array();
            $data['plat_en'] = $plat_en;
            $data['title'] = $_POST['title'];
            $data['type'] = $type;
            $data['image_url'] = $_POST['image_url'];
            $data['sort'] = $_POST['sort'];
            $data['is_show'] = $_POST['is_show'];
            $result = $this->db->where(array("id"=>$id))->update("plat_info_img",$data);
            if($result){
                $this->update_tupianziliao($plat_en,$type);
                $mssage['info']	  = '更新成功';
                $mssage['status'] = 1;
                $mssage['url']	  = site_url('interests/tupianziliao')."?key=".$plat_en."&type=".$type;
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = "";
                echo json_encode($mssage);exit;
            }
        }
        
        $plat_en = trim($_GET['key']);
        $id = trim($_GET['id']);
        $type = trim($_GET['type']);
        $item = $this->db->query("select i.*,p.name_ch from tan_plat_info_img i left join tan_plat p on p.name_en = i.plat_en where i.id = $id order by i.id limit 1")->row_array();
        $this->template->assign('item',$item);
        $this->template->assign('tt',$type);
        $this->template->assign('segment_p','index');
        $this->template->load('interests/tupianziliao_edit');
    }
    //图片资料-更新show
    function tupianziliao_setshow(){
        if($_GET){
            $mssage = array();
            $id	   = trim($_GET['id']);
            $is_show = trim($_GET['is_show']);
            $plat_en = trim($_GET['key']);
            $type = trim($_GET['type']);
            $data = array();
            $data['is_show'] = $is_show;
            $result = $this->db->where(array("id"=>$id))->update("plat_info_img",$data);
            if($result){
                $this->update_tupianziliao($plat_en,$type);
                if($is_index==1){
                    $mssage['info']	  = '显示成功';
                }else{
                    $mssage['info']	  = '隐藏成功';
                }
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
    }
    //图片资料-更新排序
    function tupianziliao_setsort(){
        if($_POST){
            $mssage = array();
            $id    = trim($_POST['id']);
            $sort  = trim($_POST['sort']);
            $plat_en = trim($_POST['key']);
            $type = trim($_POST['type']);
            if(!$id){
                $mssage['info']	  = '系统错误';
                $mssage['status'] = 0;
                $mssage['url']	  = '';
                echo json_encode($mssage);exit;
            }

            $data = array();
            $data['sort'] = $sort;
            $result = $this->db->where(array("id"=>$id))->update("plat_info_img",$data);
            if($result){
                $this->update_tupianziliao($plat_en,$type);
                $mssage['info']	  = '操作成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
    }
    //图片资料-更新del
    function tupianziliao_setdel(){
        if($_GET){
            $mssage = array();
            $id	   = trim($_GET['id']);
            $plat_en	   = trim($_GET['key']);
            $type = trim($_GET['type']);
            $this->db->where(array("id"=>$id))->delete("plat_info_img");
            $result = $this->db->affected_rows();
            if($result){
                $this->update_tupianziliao($plat_en,$type);
                $mssage['info']	  = '删除成功';
                $mssage['status'] = 1;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }else{
                $mssage['info']	  = '操作失败';
                $mssage['status'] = 0;
                $mssage['url']	  = $_SERVER['HTTP_REFERER'];
                echo json_encode($mssage);exit;
            }
        }
    }
    //更新团队介绍
    private function update_tuanduijieshao($plat_en){
        $list = $this->db->query("select * from tan_plat_team where plat_en = '$plat_en' and is_show = 1 order by sort desc,id desc ")->result_array();
        foreach ($list as $key=>$val){
            unset($list[$key]['id']);
            unset($list[$key]['plat_en']);
        }
        $data['tuanduijieshao'] = $list ? serialize($list) : "";
        $this->db->where(array("plat_en"=>$plat_en))->update("plat_info",$data);
    }
    //更新图片资料
    private function update_tupianziliao($plat_en,$type){
        $list = $this->db->query("select * from tan_plat_info_img where plat_en = '$plat_en' and type = '$type' and is_show = 1 order by sort desc,id desc ")->result_array();
        foreach($list as $key=>$val){
            unset($list[$key]['id']);
            unset($list[$key]['plat_en']);
        }
        
        if($type == "credit"){//证件资料
            $data['zhengjianziliao'] = $list ? serialize($list) : "";
        }elseif($type == "office"){//办公环境
            $data['bangonghuanjing'] = $list ? serialize($list) : "";
        }
        $this->db->where(array("plat_en"=>$plat_en))->update("plat_info",$data);
    }
}
